/**
 * Copyright(C) 2012 Luvina Software Company
 *
 * MstGroupLogicImpl.java, 2/1/2013, NgocAnh
 */
package net.luvina.manageuser.logic.impl;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import net.luvina.manageuser.dao.MstGroupDao;
import net.luvina.manageuser.hibernate.MstGroup;
import net.luvina.manageuser.logic.MstGroupLogic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * get list group
 *
 * @author la-pm Ngoc Anh
 *
 */
@Service("GroupLogic")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false, rollbackFor = { Throwable.class })
public class MstGroupLogicImpl implements MstGroupLogic {
    @Autowired
    private MstGroupDao mstGroupDao;

    public List<SelectItem> getListItemGroup(String valueDefault) {
        // return mstGroupDao.getListGroup();
        List<MstGroup> listUserGrp = this.mstGroupDao.getListGroup();
        SelectItem selectItemGroup;
        ArrayList<SelectItem> itemGroups = new ArrayList<SelectItem>();
        itemGroups.add(new SelectItem("", valueDefault));
        for (MstGroup userGrp : listUserGrp) {
            selectItemGroup = new SelectItem(userGrp.getGroupId(), userGrp
                    .getGroupName());
            itemGroups.add(selectItemGroup);
        }
        return itemGroups;
    }

}
